function closeUnionMessageConfigDiv(){
		$('#unionMessageConfigDiv').CloseDiv();
}
//配置车加意关联信息  弹窗显示
function openMessageConfig(){	
	selectUnionMessageConfigAndWriteBack();
	$('#unionMessageConfigDiv').OpenDiv();//显示弹窗		
}
//保存车意联合出单信息
function saveUnionMessageConfig(){
	//获取方案号 
	var currentPlanNo = $("#planNo").val();
	if ($("#planNo").val()==null){
		//意见险方案号为空，取财险方案号（两个页面共用）
		currentPlanNo = $("#hidepno").val();
	}
	var currentPlanName = $("#planName").val();
	var partnerNo = $("#partnerNo").val();
	if (partnerNo == null){
		//取财险的
		partnerNo = $("#partnerCode").val();
	}
	var planType = $("#unionMessageConfigPlanType").val();
	var agentType = $("#agentType").val();
	if(partnerNo == "" ||partnerNo == null){
		$.message("error","请确定合作伙伴代码");
	}
	if(currentPlanNo == "" || currentPlanNo == null){
		$.message("error","请先确定方案");
		return ;
	}
	if(currentPlanName == ""){
		$.message("error","请先确定方案名称");
		return ;
	}
	//获取机构信息
	var currentDeptNo = $("#unionMessageConfigDept").val();
	if(currentDeptNo == null || currentDeptNo == ""){
		$.message("error","请选择有效的机构代码");
		return ;
	}
	//车辆座位数区间
	var minSeatNum = parseInt($("#unionMessageConfigMinSeatNum").val()) ;
	var maxSeatNum = parseInt($("#unionMessageConfigMaxSeatNum").val()) ;
	if(maxSeatNum == "" || minSeatNum == ""){
		$.message("error","最大座位数与最小座位数不能置空，请检查");
		return ;
	}
	if(maxSeatNum < minSeatNum){
		$.message("error","最大座位数小于最小座位数，请检查");
		return ;
	}else if( maxSeatNum == '0'){
		$.message("error","最大座位数为零，请检查");
		return ;
	}else if(maxSeatNum < 0 || minSeatNum < 0){
		$.message("error","座位数不可为负，请检查");
		return ;
	}else if(maxSeatNum > 100){
		$.message("error","最大座位数最多可为99");
		return ;
	}
	// 服务代码
	var serviceCode = $("#carNlifeServiceCode").val();
	
	//获取车辆使用性质
	var natureArray = "";
	var natureCheckBoxes = document.getElementsByName("carNatureSelector");
	for( var i = 0 ; i < natureCheckBoxes.length ; i++){
		if(natureCheckBoxes[i].checked){	
			natureArray = natureArray + natureCheckBoxes[i].value;
		}
	}
	if(natureArray.length == 0){
		$.message("error","请最少选择一种车辆性质");
		return ;
	}
	var data = {planNo:currentPlanNo,deptNo:currentDeptNo,minSeat:minSeatNum,maxSeat:maxSeatNum,natureArray:natureArray,planName:currentPlanName,partnerNo:partnerNo,planType:planType,agentType:agentType,serviceCode:serviceCode};
	$.openLoading();
	$.ajax({
		url:"nlifeProductConfig/saveUnionMessageConfig",		
		type:'POST',
		async:false,
		dataType:'json',
		data:data,
		success:function(page){
			if(page.result == "success"){
				//存储/更新成功
				$.message("success",page.message);
			}else{		
				//存储/更新失败
				$.message("error",page.message);
			}
			$.closeLoading();	
		},
	 	error:function(page){
	 		$.message("error","系统异常 请联系管理员");
	 		$.closeLoading();
		}
	})
}



//查询车加健联合信息 并回写至页面上
//在初次加载车加健联合信息，或者更改机构时触发
function selectUnionMessageConfigAndWriteBack(){
	
	//先给已选择的内容都清除了
	//座位数
	$("#unionMessageConfigMinSeatNum").val("");
	$("#unionMessageConfigMaxSeatNum").val("");
	$("#carNlifeServiceCode").val("");
	//适用车辆性质
	$('input[name="carNatureSelector"]').removeAttr('checked');
	
	var currentPlanNo = $("#planNo").val();
	if ($("#planNo").val()==null){
		//意见险方案号为空，取财险方案号（两个页面共用）
		currentPlanNo = $("#hidepno").val();
	}
	var currentDeptNo = $("#unionMessageConfigDept").val();
	var currentPlanType = $("#unionMessageConfigPlanType").val();
	if(currentPlanNo == "" || currentDeptNo == ""){
		//这属于啥也没选，不做下一步动作
		return ;
	}
	var data = {planNo:currentPlanNo,deptCode:currentDeptNo,planType:currentPlanType};
	$.openLoading();
	$.ajax({
		url:"nlifeProductConfig/selectUnionMessageConfig",		
		type:'POST',
		async:false,
		dataType:'json',
		data:data,
		success:function(page){
			if(page.result == "success"){
				//查到了
				var config = page.data[0];
				//回写 车辆性质 车辆座位数区间
				$("#unionMessageConfigMinSeatNum").val(config.minSeat);
				$("#unionMessageConfigMaxSeatNum").val(config.maxSeat);
				$("#carNlifeServiceCode").val(config.serviceCode);
				var natureStr = config.vhlTyp;
				//截取子串 做遍历
				if(i%6 == 0){
					for(var i=0;i<natureStr.length/6;i++){
						var nature = natureStr.substring(i*6,(i+1)*6);
						$('input[name="carNatureSelector"][value='+nature+']').attr("checked","checked");				
					}	
				}else {
					//有某个码值是9位的
					var x = 0;
					for(var i=0;i<natureStr.length/6;i++){
						var nature = natureStr.substring(i*6+x,(i+1)*6+x);
						if(nature == '301006' ){
							x = 3;
							$('input[name="carNatureSelector"][value='+nature + '001' +']').attr("checked","checked");
						}else {
							$('input[name="carNatureSelector"][value='+nature+']').attr("checked","checked");	
						}			
					} 
				}
				
				
			}else{		
				//$.message("error","系统异常 请联系管理员");
			}
			$.closeLoading();	
		},
	 	error:function(page){
	 		$.message("error","系统异常 请联系管理员");
	 		$.closeLoading();
		}
	})		
}
//清除增值服务相关的input的值
function clearAddService(){
	$('#addedServiceCode').val('');
	$('#addedServiceName').val('');
	$('#addedServiceCount').val('');
	$('#serviceTypeSelect').val('');	
}
//兼容ie的startsWith方法
function startsWith(str, prefix) {
    return str.slice(0, prefix.length) === prefix;
}

//业务来源1修改，变更来源2的码值
function changeFirstbusinessNature(obj){
	//清除来源2的所有选项
	$('select[id="businessNature2"]').empty();
	var selectElement = document.getElementById("businessNature2");
	$.openLoading();
	$.ajax({
		url:"nlifePlanConfig/getBusinessNature2",		
		type:'POST',
		async:false,
		dataType:'json',
		data:{code:obj.value},
		success:function(list){
			for(var i in list){
				var option = document.createElement("option");
				option.text = list[i].codeName;
				option.value = list[i].code;
				selectElement.add(option);		
			}
			$.closeLoading();	
		},
	 	error:function(page){
	 		$.message("error","系统异常 请联系管理员");
	 		$.closeLoading();
		}
	})
}
//统信渠道一级修改，加载二级字典
function txChannelChange(obj){
	//清除二级的所有选项
	$('select[id="txChannel2nd"]').empty();
	var selectElement = document.getElementById("txChannel2nd");
	$.openLoading();
	$.ajax({
		url:"nlifePlanConfig/getTxChannel2nd",		
		type:'POST',
		async:false,
		dataType:'json',
		data:{code:obj.value},
		success:function(list){
			for(var i in list){
				var option = document.createElement("option");
				option.text = list[i].codeName;
				option.value = list[i].code;
				selectElement.add(option);		
			}
			$.closeLoading();	
		},
	 	error:function(page){
	 		$.message("error","系统异常 请联系管理员");
	 		$.closeLoading();
		}
	})
}

//燕赵新增 根据升级产品数量加载特约框体
function queryUpdateInformation(prodCode){
	//首先将已经加载的内容清除掉
	$("#updateInfomationDiv").find("tr").remove();
	
	$.openLoading();
	$.ajax({
		url : "nlifePlanConfig/queryUpdateInformation",
		type : 'POST',
		async : true,
		data:{prodCode:prodCode},
		dataType:'json',
		success:function(list){
			if(list != null){
				var tableContent = "";
				if(list.length > 0){
					for(var i=0 ; i<list.length ; i++){
						tableContent += "<tr>" +
								"<th>"+list[i].CODE_NAME+"特别约定：</th>" +
								"<td colspan='3'><textarea name='updateSpecialArran' id='"+
								"specialArran"+list[i].HOOKPRODUCT
								+"' rows='5' class='textarea_1' style='resize:none;'>"+list[i].SPICAL_ARRAN+"</textarea></td>"
								"</tr>";
					}
					$("#updateInfomationDiv").append(tableContent);
				}
				
			}
		}
	});
	$.closeLoading();
}
//绿色产业相关字段根据产品个团标识进行显隐处理
function prodCodeChanged(prodCode){
	$.ajax({
		url : "nlifePlanConfig/queryAppType",
		type : 'POST',
		async : true,
		data:{prodCode:prodCode},
		dataType:'json',
		success:function(data){
				if(data == 1){
					//团单
					$("#greenIndustryInfo").show();
				}else {
					$("#greenIndustryInfo").hide();
				}
			}
		});
	}